<?php
/*******************************************************************************
*  Title: Help Desk Software HESK
*  Version: 2.2 from 9th June 2010
*  Author: Klemen Stirn
*  Website: http://www.hesk.com
********************************************************************************
*  COPYRIGHT AND TRADEMARK NOTICE
*  Copyright 2005-2010 Klemen Stirn. All Rights Reserved.
*  HESK is a registered trademark of Klemen Stirn.

*  The HESK may be used and modified free of charge by anyone
*  AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
*  By using this code you agree to indemnify Klemen Stirn from any
*  liability that might arise from it's use.

*  Selling the code for this program, in part or full, without prior
*  written consent is expressly forbidden.

*  Using this code, in part or full, to create derivate work,
*  new scripts or products is expressly forbidden. Obtain permission
*  before redistributing this software over the Internet or in
*  any other medium. In all cases copyright and header must remain intact.
*  This Copyright is in full effect in any country that has International
*  Trade Agreements with the United States of America or
*  with the European Union.

*  Removing any of the copyright notices without purchasing a license
*  is expressly forbidden. To remove HESK copyright notice you must purchase
*  a license for this script. For more information on how to obtain
*  a license please visit the page below:
*  https://www.hesk.com/buy.php
*******************************************************************************/

define('IN_SCRIPT',1);
define('HESK_PATH','./');

/* Get all the required files and functions */
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
require(HESK_PATH . 'inc/database.inc.php');

hesk_dbConnect();

global $hesk_settings, $hesklang;

hesk_session_start();
if ($hesk_settings['secimg_use'])
{
	$_SESSION['secnum']=rand(10000,99999);
	$_SESSION['checksum']=sha1($_SESSION['secnum'].$hesk_settings['secimg_sum']);
}

/* Print header */
$hesk_settings['tmp_title'] = $hesk_settings['hesk_title'] . ' - ' . $hesklang['register'];
require_once(HESK_PATH . 'inc/header.inc.php');
?>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td><span class="smaller"><a href="<?php echo $hesk_settings['site_url']; ?>" class="smaller"><?php echo $hesk_settings['site_title']; ?></a> &gt; <a href="<?php echo $hesk_settings['hesk_url']; ?>" class="smaller"><?php echo $hesk_settings['hesk_title']; ?></a> &gt; <?php echo $hesklang['register']; ?></span></td>
  </tr>
</table>
</td>
</tr>
<tr>
  <td><?php
/* This will handle error, success and notice messages */
hesk_handle_messages();
?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="7" height="7"><img src="img/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
        <td class="roundcornerstop"></td>
        <td><img src="img/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
      </tr>
      <tr>
        <td class="roundcornersleft">&nbsp;</td>
        <td><!-- START FORM -->
          <p><?php echo $hesklang['use_form_register']; ?> <font class="important"> *</font></p>
          <form method="post" action="register_account.php" name="form1" enctype="multipart/form-data">
            <!-- Contact info -->
            <table border="0" width="100%">
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['email']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="text" name="email" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_email'])) {echo stripslashes(hesk_input($_SESSION['c_email']));} ?>" /></td>
              </tr>
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['password']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="password" name="password" size="40" maxlength="50" value="" /></td>
              </tr>
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['repass']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="password" name="repass" size="40" maxlength="50" value="" /></td>
              </tr>
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['profile_pic']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="file" name="profpic" size="40" /></td>
              </tr>
              <tr>
                <td style="text-align:right" width="150"></td>
                <td width="80%">Maximum size 50 Kb (jpg)</td>
              </tr>
            </table>
            <hr />
            <!-- Department and priority -->
            <table border="0" width="100%">
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['firstname']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="text" name="firstname" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_firstname'])) {echo stripslashes(hesk_input($_SESSION['c_firstname']));} ?>" /></td>
              </tr>
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['lastname']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="text" name="lastname" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_lastname'])) {echo stripslashes(hesk_input($_SESSION['c_lastname']));} ?>" /></td>
               </tr>
               <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['gender']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%">
                    <select name="gender">
                        <option value="1" <?php if(isset($_SESSION['c_gender'])) { echo ($_SESSION['c_gender'] == 1) ? 'selected="selected"' : ''; };?> ><?php echo $hesklang['male'];?></option>
                        <option value="2" <?php if(isset($_SESSION['c_gender'])) { echo ($_SESSION['c_gender'] == 2) ? 'selected="selected"' : ''; };?> ><?php echo $hesklang['female'];?></option>
                    </select>
               </tr> 
               <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['handphone']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%"><input type="text" name="handphone" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_handphone'])) {echo stripslashes(hesk_input($_SESSION['c_handphone']));} ?>" /></td>
               </tr> 
            </table>
            <hr />
            <table border="0" width="100%"> 
               <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['province']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%">
                    <select name="province" onchange="update_city('<?php echo HESK_PATH;?>',this.options[this.selectedIndex].value)">
                        <?php
                            $query = 'SELECT * FROM hesk_propinsi';
                            $result = hesk_dbQuery($query);
                            while ($prov = hesk_dbFetchAssoc($result)) {
                        ?>
                        <option value="<?php echo $prov['id_propinsi'];?>" <?php if(isset($_SESSION['c_province'])) { echo ($_SESSION['c_province'] == $prov['id_propinsi']) ? 'selected="selected"' : ''; };?> ><?php echo $prov['propinsi'];?></option>
                        <?php } ?>
                    </select>
                </td>
              </tr>  
               <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['city']; ?>
                    <font class="important"> * </font>
                    :</td>
                <td width="80%">
                    <select id="city-selection" name="city">
                        <?php
                            if(isset($_SESSION['c_province'])){
                                $id_province = $_SESSION['c_province'];
                            } else {
                                $id_province = 7;
                            }
                            $query = 'SELECT * FROM hesk_kota WHERE id_propinsi='.$id_province;
                            $result = hesk_dbQuery($query);
                            while ($city = hesk_dbFetchAssoc($result)) {
                        ?>
                        <option value="<?php echo $city['id_kota'];?>" <?php if(isset($_SESSION['c_city'])) { echo ($_SESSION['c_city'] == $city['id_kota']) ? 'selected="selected"' : ''; };?> ><?php echo $city['kota'];?></option>
                        <?php } ?>
                    </select>
                </td>
               </tr>
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['address']; ?>
                    <font class="important"> * </font>
                    : </td>
                <td width="80%"><input type="text" name="address" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_address'])) {echo stripslashes(hesk_input($_SESSION['c_address']));} ?>" /></td>
               </tr>
           </table>
            <hr />
            <table border="0" width="100%">
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['company']; ?>:</td>
                <td width="80%"><input type="text" name="company" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_company'])) {echo stripslashes(hesk_input($_SESSION['c_company']));} ?>" /></td>
              </tr>
              <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['phone']; ?>:</td>
                <td width="80%"><input type="text" name="phone" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_phone'])) {echo stripslashes(hesk_input($_SESSION['c_phone']));} ?>" /></td>
               </tr>  
               <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['fax']; ?>:</td>
                <td width="80%"><input type="text" name="fax" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_fax'])) {echo stripslashes(hesk_input($_SESSION['c_fax']));} ?>" /></td>
               </tr> 
               <tr>
                <td style="text-align:right" width="150"><?php echo $hesklang['website']; ?>:</td>
                <td width="80%"><input type="text" name="website" size="40" maxlength="50" value="<?php if (isset($_SESSION['c_website'])) {echo stripslashes(hesk_input($_SESSION['c_website']));} ?>" /></td>
               </tr> 
            </table>
            <hr />
            <?php
			if ($hesk_settings['question_use'] || $hesk_settings['secimg_use'])
			{
			?>
            <!-- Security checks -->
            <div align="center">
              <table border="0">
                <tr>
                  <td>
				    <?php
					if ($hesk_settings['question_use'])
					{
						$value = '';
						if (isset($_SESSION['c_question']))
						{
							$value = stripslashes(hesk_input($_SESSION['c_question']));
						}
						echo '<p>'.$hesk_settings['question_ask'].' <font class="important">*</font><br /><input type="text" name="question" size="10" value="'.$value.'"  /></p>';
					}
			
					if ($hesk_settings['secimg_use'])
					{
						echo '<p><img src="print_sec_img.php?'.rand(10000,99999).'" width="150" height="40" alt="'.$hesklang['sec_img'].'" border="1" /><br />'.
						$hesklang['sec_enter'].': <font class="important">*</font> <input type="text" name="mysecnum" size="10" maxlength="5" /></p>';
					}
					?></td>
                </tr>
              </table>
            </div>
            <hr />
            <?php
			}
			?>
            <!-- Submit -->
            <div align="center">
              <table border="0">
                <tr>
                  <td>
                    <p align="center">
                      <input type="hidden" name="token" value="<?php hesk_token_echo(); ?>" />
                      <input type="submit" value="<?php echo $hesklang['register']; ?>" class="orangebutton"  onmouseover="hesk_btn(this,'orangebuttonover');" onmouseout="hesk_btn(this,'orangebutton');" />
                    </p>
                  </td>
                </tr>
              </table>
            </div>
          </form>
          <!-- END FORM --></td>
        <td class="roundcornersright">&nbsp;</td>
      </tr>
      <tr>
        <td><img src="img/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
        <td class="roundcornersbottom"></td>
        <td width="7" height="7"><img src="img/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
      </tr>
    </table>
